﻿using System.Text;
using TY.UC.Common;
using TY.UC.Common.Extension;
using TY.UC.Http;

namespace TY.UT.Common.Http
{
    /// <summary>
    /// TY 请求加密（与c2b的加密一直）
    /// </summary>
    public class ParamEncryption
    {
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="m">请求参数</param>
        /// <param name="token">公钥</param>
        /// <param name="privatetoken">私钥</param>
        /// <returns>加密结果</returns>
        public  static string GetParamSign(TyRequestModel m,string token=null,string privatetoken=null)
        {
            if (string.IsNullOrEmpty(token))
            {
                token = "AppToken".GetStrValue();
            }
            //没有私钥时，启用公匙
            if (string.IsNullOrEmpty(privatetoken))
            {
                privatetoken = token;
            }
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0}action{1}app_key{2}data{3}format{4}platform{5}sign_method{6}timestamp{7}version{8}{9}",
                            token, m.Action, m.AppKey, m.Data.JsonSe(), m.Format, m.Platform, m.SignMethod, m.Timestamp, m.Version, privatetoken);
            return Md5Helper.Get32Md5Str(sb.ToString());
        }
      
    }
}
